#ifndef MY_QT_DEF_H
#define MY_QT_DEF_H
#include "qglobal.h"
#include <QDebug>
#include <QDateTime>
#include <QTextEdit>
#include <QDate>
#include <QTimer>
#include <QTime>
#include <QValueAxis>
#include <QList>
#include <QSplineSeries>
#include <QString>
#include <QChart>
#include <QChartView>
QT_CHARTS_USE_NAMESPACE
#include <QThread>
#include <QMutexLocker>
#include <QMutex>
#include <QCoreApplication>
#include <QElapsedTimer>
#include <QSerialPort>
#include <QSerialPortInfo>
#include <QScreen>
#include <QPixmap>
#include <QGuiApplication>
#include <QDir>
#include <QtGui>
#include <QMouseEvent>
#include <QPaintEvent>
#include <QResizeEvent>
#include <QColor>
#include <QWidget>
#include <QPixmap>
#include <QPoint>
#include <QPainter>
#include <QPalette>
#include <QMainWindow>

void TextEdit_Append(QTextEdit *text,QString str);
void MessageOutput_Callback(QString strMessage);
void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg);
void Init_MessageOutput(bool EnableNotDisable);
void Screen_Win(WId wid,QString str);
bool Judg_Dir_Exist(QString fullPath);
bool Judg_File_Exist(QString fullPath);
void File_Write_Text(QString fullPath,QString str);
void File_Append_Text(QString fullPath,QString str);

typedef void (* MY_QT_CALLBACK) (void * pCBParam,uint32_t Event,void * pArg);

typedef struct
{
    float min;
    float max;

    QString tittle;
    QString format;
    Qt::Alignment alignment;

    QValueAxis *axis;
}MY_QChartView_Float_Axis_Struct;

QList<uint8_t> Trans_Hex_Str_to_Buf(QString str);
QString Trans_Hex_Buf_to_Str(QList<uint8_t> buf);
QString Trans_Hex_Buf_to_Str(uint8_t* buf,uint32_t size);

//splineSeries曲线实例化（折线用QLineSeries）
typedef struct
{
    int maxSize;
    QList<float> data;
    QString tittle;

    MY_QChartView_Float_Axis_Struct X;
    MY_QChartView_Float_Axis_Struct Y;

    //上面是必配置的参数 下面是指针类型
    QLineSeries *Series;

    QChart *chart;
    QChartView *chartView;
}MY_QChartView_Float_Struct;

void Init_MY_QChartView_Float_Axis_Struct(MY_QChartView_Float_Axis_Struct *Stu,QChart *chart);
void Init_MY_QChartView_Float_Struct(MY_QChartView_Float_Struct *Stu);
void Add_MY_QChartView_Float_Value(MY_QChartView_Float_Struct *Stu,float value);
void Add_Remove_MY_QChartView_Float_Value(MY_QChartView_Float_Struct *Stu,float value);
void Show_MY_QChartView_Float_Struct(MY_QChartView_Float_Struct *Stu);

class MY_Timer;
class MY_Timer : public QObject
{
    Q_OBJECT
private:
    MY_QT_CALLBACK pfCallback;
    uint32_t Time_Out;
    bool Thread_Flag;
    QThread Thread;
    bool Timer_Flag;
public slots:
    void timerTimeOut(void)
    {
        pfCallback(this,0,NULL);
    }

    void Judg_doWork(void)
    {
        this->Timer.stop();
        Timer_Flag=false;
    }

signals:
    void startWork(void);

public:
    QTimer Timer;

    uint32_t Get_Time_Out(void)
    {
        return this->Time_Out;
    }

    void Change_Time_Out(uint32_t time_out)
    {
        Stop_Timer();
        this->Time_Out=time_out;
        this->Timer.setInterval(this->Time_Out);
    }

    void Stop_Timer(void)
    {
        if(Timer_Flag)
        {
            if(this->Thread_Flag)
            {
                emit this->startWork();
                QElapsedTimer t;
                t.start();
                while(t.elapsed()<5000 && Timer_Flag){
                    QCoreApplication::processEvents();
                }
                this->Thread.quit();
            }
            else
            {
                Timer_Flag=false;
                this->Timer.stop();
            }
        }
    }

    void Start_Timer(void)
    {
        if(!Timer_Flag)
        {
            Timer_Flag=true;
            if(this->Thread_Flag)
            {
                this->Thread.start();
            }
            else
            {
                this->Timer.start();
            }
        }
    }

    MY_Timer(MY_QT_CALLBACK const pfunc,uint32_t time_out,bool Thread_EnableNotDisable = false)
    {
        this->Timer_Flag=false;
        pfCallback=pfunc;
        this->Time_Out=time_out;
        this->Timer.setInterval(this->Time_Out);
        this->Thread_Flag= Thread_EnableNotDisable;

        if(this->Thread_Flag)
        {
            this->Timer.moveToThread (&this->Thread);
            this->moveToThread(&this->Thread);
            connect(&this->Thread, SIGNAL(started()), &this->Timer, SLOT(start()));
            connect(this, SIGNAL(startWork()), this, SLOT(Judg_doWork()));
            connect(&this->Timer, SIGNAL(timeout()), this, SLOT(timerTimeOut()), Qt::DirectConnection);
        }
        else
        {
            connect(&this->Timer, SIGNAL(timeout()), this, SLOT(timerTimeOut()));
        }
    }

    ~MY_Timer()
    {
        Stop_Timer();
        this->Thread.deleteLater();
    }
};

//QObject的多线程示例
class MY_Thread_Worker;
class MY_Thread_Worker : public QObject
{
    Q_OBJECT
private:
    QMutex lock;
    bool isCanRun;
    bool isCanStart;
    MY_QT_CALLBACK pfCallback;
public slots:
    void Judg_doWork(void)
    {
        this->isCanRun=true;
        //执行
        while(this->isCanRun)
        {
            QMutexLocker locker(&this->lock);
            pfCallback(this,0,NULL);
        }
        isCanStart=true;
    }

signals:
    void startWork(void);
public:
    void * pArg;
    QThread *workerThread;

    void stopWork(bool Wait_Flag)
    {
        this->isCanRun = false;
        if(Wait_Flag)
        {
            QMutexLocker locker(&this->lock);
        }
    }

    bool startThread(void)
    {
        if(!isCanRun && isCanStart)
        {
            isCanStart=false;
            workerThread->start();
            emit this->startWork();
            return true;
        }
        return false;
    }

    bool stopThread(bool Wait_Flag)
    {
        if(workerThread->isRunning())
        {
            stopWork(Wait_Flag);
            return true;
        }
        return false;
    }

    void closeThread(void)
    {
        stopThread(false);
        this->workerThread->quit();
        this->workerThread->wait();
    }

    MY_Thread_Worker(MY_QT_CALLBACK const pfunc,QThread * worker_Thread = nullptr)
    {
        pfCallback=pfunc;
        pArg=nullptr;
        if(!worker_Thread)
        {
            this->workerThread = new QThread;
        }
        else
        {
            this->workerThread = worker_Thread;
        }
        this->moveToThread(workerThread);
        this->stopWork(false);
        isCanStart=true;
        connect(workerThread, SIGNAL(finished()),this, SLOT(deleteLater()));
        connect(workerThread, SIGNAL(finished()), workerThread, SLOT(deleteLater()));
        connect(this, SIGNAL(startWork()), this, SLOT(Judg_doWork()));
        // connect(this, SIGNAL(startWork(QString)), worker, SLOT(Judg_doWork(QString)));  主窗口发送函数
        // connect(worker, SIGNAL(resultReady(QString)),this, SLOT(handleResults(QString)));  主窗口接收函数
    }

    ~MY_Thread_Worker()
    {
        closeThread();
    }
};

class MY_SerialPort_Thread;
class MY_SerialPort_Thread : public QObject
{
    Q_OBJECT
private:
    QMutex lock;
    bool isCanRun;
    bool isCanStart;
    bool Thread_Flag;

    MY_QT_CALLBACK pfCallback;
public slots:
    void SerialPort_RX(void)
    {
        SerialPort_RX_Ready_Callback(this);
    }

    void Callback_SerialPort_RX(void)
    {
        pfCallback(this,0,NULL);
    }

    void RX_Thread(void)
    {
        this->isCanRun=true;
        //执行
        while(isCanRun)
        {
            QMutexLocker locker(&this->lock);
            if(SerialPort.waitForReadyRead(1000))
            {
                SerialPort_RX_Thread_Callback(this);
            }
        }
        isCanStart=true;
    }

    void Callback_RX_Thread(void)
    {
        this->isCanRun=true;
        //执行
        while(isCanRun)
        {
            QMutexLocker locker(&this->lock);
            if(SerialPort.waitForReadyRead(1000))
            {
                pfCallback(this,1,NULL);
            }
        }
        isCanStart=true;
    }

signals:
    void Start_RX_Thread(void);

public:
    QSerialPort SerialPort;
    QList<QString> SerialPort_List;
    QString SerialPort_Name;
    uint32_t BaudRate;
    uint8_t DataBits;
    uint8_t StopBits;
    QSerialPort::Parity Parity;
    QSerialPort::FlowControl FlowControl;

    bool Open_Flag;
    uint8_t RX_Data;
    uint8_t *RX_Buf;
    uint32_t RX_Buf_Size;
    uint32_t RX_Flag;

    QThread workerThread;

    void Stop_Port(uint8_t TX_RX_All)
    {
        switch(TX_RX_All)
        {
            case 0:SerialPort.clear(QSerialPort::Output);break;
            case 1:SerialPort.clear(QSerialPort::Input);break;
            default:SerialPort.clear();SerialPort.flush();break;
        }
    }

    void Scan_SerialPort(void)
    {
        SerialPort_List.clear();
        foreach (const QSerialPortInfo &info,QSerialPortInfo::availablePorts())
        {
            SerialPort_List.append(info.portName());
        }
    }

    void Clean_RX(void)
    {
        RX_Flag=0;
        RX_Data=0;
        memset(RX_Buf,0,RX_Buf_Size);
    }

    void Reset_SerialPort(void)
    {
        Scan_SerialPort();
        BaudRate=115200;
        DataBits=8;
        StopBits=1;
        Parity=QSerialPort::NoParity;
        FlowControl = QSerialPort::NoFlowControl;
        if(Open_Flag)
        {
            Stop_Port(2);
        }
        Clean_RX();
    }

    bool Ctrl_SerialPort(bool OpenNotClose)
    {
        if(OpenNotClose)
        {

            SerialPort.setPortName(SerialPort_Name);
            SerialPort.setBaudRate(BaudRate);
            SerialPort.setFlowControl(FlowControl);

            switch(DataBits)
            {
            case 5:SerialPort.setDataBits(QSerialPort::Data5);break;
            case 6:SerialPort.setDataBits(QSerialPort::Data6);break;
            case 7:SerialPort.setDataBits(QSerialPort::Data7);break;
            case 8:SerialPort.setDataBits(QSerialPort::Data8);break;
            default:break;
            }

            SerialPort.setParity(Parity);

            switch(StopBits)
            {
            case 1:SerialPort.setStopBits(QSerialPort::OneStop);break;
            case 2:SerialPort.setStopBits(QSerialPort::TwoStop);break;
            case 3:SerialPort.setStopBits(QSerialPort::OneAndHalfStop);break;
            default:break;
            }

            if (!SerialPort.open(QIODevice::ReadWrite))
            {
                return false;
            }
            Open_Flag=true;
            if(this->Thread_Flag)
            {
                startThread();
            }
            return true;
        }

        stopThread(true);
        Open_Flag=false;
        SerialPort.close();        
        return true;
    }

    uint32_t SerialPort_TX_Sequence(uint8_t *buf,uint32_t size)
    {
        if(Open_Flag)
        {
            return SerialPort.write((char *)buf,size);
        }
        return 0;
    }

    uint32_t SerialPort_TX(uint8_t *buf,uint32_t size)
    {
        if(Open_Flag)
        {
            SerialPort.clear(QSerialPort::Output);
            return SerialPort.write((char *)buf,size);
        }
        return 0;
    }

    virtual void SerialPort_RX_Ready_Callback(MY_SerialPort_Thread *port)
    {
        Q_UNUSED(port);
        foreach (const uint8_t i,port->SerialPort.readAll())
        {
            port->RX_Data=i;
            SerialPort_RX_Callback(port);
        }
    }

    virtual void SerialPort_RX_Thread_Callback(MY_SerialPort_Thread *port)
    {
        Q_UNUSED(port);
        foreach (const uint8_t i,port->SerialPort.readAll())
        {
            port->RX_Data=i;
            SerialPort_RX_Callback(port);
        }
    }

    virtual void SerialPort_RX_Callback(MY_SerialPort_Thread *port)
    {
        Q_UNUSED(port);
        qDebug()<<port->RX_Data;
    }

    void stopWork(bool Wait_Flag)
    {
        this->isCanRun = false;
        if(Wait_Flag)
        {
            QMutexLocker locker(&this->lock);
        }
    }

    bool startThread(void)
    {
        if(!isCanRun && isCanStart)
        {
            isCanStart=false;
            workerThread.start();
            emit this->Start_RX_Thread();
            return true;
        }
        return false;
    }

    bool stopThread(bool Wait_Flag)
    {
        if(workerThread.isRunning())
        {
            stopWork(Wait_Flag);
            return true;
        }
        return false;
    }

    void closeThread(void)
    {
        stopThread(false);
        this->workerThread.quit();
        this->workerThread.wait();
    }

    MY_SerialPort_Thread(uint32_t Buf_Size=256,bool ThreadNotNormal=false,MY_QT_CALLBACK const pfunc=nullptr)
    {
        pfCallback=pfunc;
        SerialPort_Name="";
        Open_Flag=false;
        RX_Buf_Size = Buf_Size;
        RX_Buf = new uint8_t[RX_Buf_Size];
        SerialPort.setReadBufferSize(RX_Buf_Size);
        this->Thread_Flag = ThreadNotNormal;
        Reset_SerialPort();
        if(Thread_Flag)
        {
            this->moveToThread(&workerThread);
            this->stopWork(false);
            isCanStart=true;
            connect(&workerThread, SIGNAL(finished()),this, SLOT(deleteLater()));
            connect(&workerThread, SIGNAL(finished()), &workerThread, SLOT(deleteLater()));
            if(pfCallback)
            {
                connect(this, SIGNAL(Start_RX_Thread()), this, SLOT(Callback_RX_Thread()));
            }
            else
            {
                connect(this, SIGNAL(Start_RX_Thread()), this, SLOT(RX_Thread()));
            }
        }
        else
        {            
            if(pfCallback)
            {
                connect(&this->SerialPort, SIGNAL(readyRead()),this, SLOT(Callback_SerialPort_RX()));
            }
            else
            {
                connect(&this->SerialPort, SIGNAL(readyRead()),this, SLOT(SerialPort_RX()));
            }
        }
    }

    ~MY_SerialPort_Thread()
    {
        Open_Flag=false;
        SerialPort.close();
        delete RX_Buf;
        closeThread();
    }
};

class MY_Display;
class MY_Display : public QWidget
{
    Q_OBJECT
public:
    MY_Display(QWidget *parent = nullptr)
    {
        widget = nullptr;
        setAutoFillBackground (true);      //对窗体背景色的设置
        setPalette(QPalette(Qt::white));
        setMinimumSize(800,600);          //设置绘制区窗体的最小尺寸
        pix =new QPixmap (size());         //对此QPixmap对象用于准备随时接收绘制的内容
        pix->fill(Qt::white);             //填充背景色为白色

        connect(this, SIGNAL(goto_setStyle(int)),this, SLOT(setStyle(int)),Qt::QueuedConnection);
        connect(this, SIGNAL(goto_setWidth(int)),this, SLOT(setWidth(int)),Qt::QueuedConnection);
        connect(this, SIGNAL(goto_setColor(QColor)),this, SLOT(setColor(QColor)),Qt::QueuedConnection);
        connect(this, SIGNAL(goto_setBack(QColor)),this, SLOT(setBack(QColor)),Qt::QueuedConnection);
        connect(this, SIGNAL(goto_clear()),this, SLOT(clear()),Qt::QueuedConnection);

        connect(this, SIGNAL(goto_drawPoint(QPoint)),this, SLOT(drawPoint(QPoint)),Qt::QueuedConnection);
        connect(this, SIGNAL(goto_drawPoints(QPoint*,int)),this, SLOT(drawPoints(QPoint*,int)),Qt::QueuedConnection);
        connect(this, SIGNAL(goto_drawLine(QPoint,QPoint)),this, SLOT(drawLine(QPoint,QPoint)),Qt::QueuedConnection);

        connect(this, SIGNAL(goto_setTextStyle(int)),this, SLOT(setTextStyle(int)),Qt::QueuedConnection);
        connect(this, SIGNAL(goto_setTextFont(QString,int)),this, SLOT(setTextFont(QString,int)),Qt::QueuedConnection);
        connect(this, SIGNAL(goto_drawText(QRectF,QString)),this, SLOT(drawText(QRectF,QString)),Qt::QueuedConnection);

        connect(this, SIGNAL(goto_fillRect(QPoint,QPoint)),this, SLOT(fillRect(QPoint,QPoint)),Qt::QueuedConnection);

        this->setStyle(1);
        this->setWidth(0); //初始化线宽
        this->setColor(Qt::black);            // 初始化颜色
        this->setBack(Qt::white);

        this->setTextFont("Arial", 20);
        this->setTextStyle(Qt::AlignCenter);

        if (parent!=nullptr )
        {
            widget = parent;
            setParent(parent,Qt::Widget);
            widget->setAutoFillBackground (true);      //对窗体背景色的设置
            widget->setPalette(QPalette(Qt::white));
            win_upsize();
            win_update();
        }
        else
        {
            show();
        }
    }
    ~MY_Display(void)
    {
        delete pix;
    }


    QList<QPoint> get_lastPoints(void)
    {
        QList<QPoint> p;
        p.append(startPos);
        p.append(endPos);
        p.append(doublePos);
        return p;
    }

    void mousePressEvent(QMouseEvent *event)
    {
        QPoint p = event->pos();
        startPos = p;
        movePos = p;
        drawPoint(p);
        emit mouse_signal(0,p);        
    }
    void mouseMoveEvent(QMouseEvent *event)
    {
        QPoint p = event->pos();
        drawLine(movePos,p);
        movePos=p;                   //更新鼠标的当前位置，为下次绘制做准备
        emit mouse_signal(1,p);
    }
    void mouseReleaseEvent(QMouseEvent *event)
    {
        QPoint p = event->pos();
        endPos = p;
        emit mouse_signal(2,p);
    }

    void mouseDoubleClickEvent(QMouseEvent *event)
    {
        QPoint p = event->pos();
        doublePos = p;
        win_upsize();
        emit mouse_signal(3,p);
    }

    void paintEvent(QPaintEvent *)
    {
        QPainter painter(this);
        painter.drawPixmap(QPoint(0,0),*pix);
    }

    void resizeEvent(QResizeEvent *event)
    {
        if(height()>pix->height()||width()>pix->width())  //(a)
        {
            QPixmap *newPix = new QPixmap (size());   //创建一个新的 QPixmap 对象
            newPix->fill(back_color);     //填充新 QPixmap 对象 newPix 的颜色为白色背景色
            QPainter p(newPix);
            p.drawPixmap(QPoint(0,0),*pix);  //在 newPix 中绘制原 pix 中的内容
            delete pix;
            pix = newPix;                    //将 newPix 赋值给 pix 作为新的绘制图形接收对象
        }
        QWidget::resizeEvent(event);        //／完成其余的工作
    }

signals:
    void goto_setStyle(int s);
    void goto_setWidth(int w);
    void goto_setColor(QColor c);
    void goto_clear(void);
    void goto_setBack(QColor c);

    void goto_setTextStyle(int text_style);
    void goto_setTextFont(QString strfont,int size);

    void goto_drawText(QRectF rectangle,QString text);
    void goto_drawPoint(QPoint p);
    void goto_drawPoints(QPoint *p,int pointCount);
    void goto_drawLine(QPoint p1,QPoint p2);

    void mouse_signal(int mode,QPoint p);

    void goto_fillRect(QPoint p1,QPoint p2);
public slots:

    void drawText(QRectF rectangle,QString text)
    {
        QPainter *painter= new QPainter;   //新建一个 QPainter 对象
        QPen pen;                          //新建一个 QPen 对象
        pen.setStyle((Qt::PenStyle)style);//(a)
        pen.setWidth(weight);                 //设置画笔的线宽值
        pen.setColor(color);                  //设置画笔的颜色
        painter->begin(pix);                  //(b)
        painter->setPen(pen);                 //将 QPen 对象应用到绘制对象中
        painter->setFont(textFont);
        painter->drawText(rectangle,textStyle,text);
        painter->end();
        win_update();                            //重绘绘制区窗体
        delete painter;
    }

    void drawPoint(QPoint p)
    {
        QPainter *painter= new QPainter;   //新建一个 QPainter 对象
        QPen pen;                          //新建一个 QPen 对象
        pen.setStyle((Qt::PenStyle)style);//(a)
        pen.setWidth(weight);                 //设置画笔的线宽值
        pen.setColor(color);                  //设置画笔的颜色
        painter->begin(pix);                  //(b)
        painter->setPen(pen);                 //将 QPen 对象应用到绘制对象中
        painter->drawPoint(p);
        painter->end();
        win_update();                            //重绘绘制区窗体
        delete painter;
    }
    void drawPoints(QPoint *p,int pointCount)
    {
        QPainter *painter= new QPainter;   //新建一个 QPainter 对象
        QPen pen;                          //新建一个 QPen 对象
        pen.setStyle((Qt::PenStyle)style);//(a)
        pen.setWidth(weight);                 //设置画笔的线宽值
        pen.setColor(color);                  //设置画笔的颜色
        painter->begin(pix);                  //(b)
        painter->setPen(pen);                 //将 QPen 对象应用到绘制对象中
        painter->drawPoints(p,pointCount);
        painter->end();
        win_update();                            //重绘绘制区窗体
        delete painter;
    }
    void drawLine(QPoint p1,QPoint p2)
    {
        QPainter *painter= new QPainter;   //新建一个 QPainter 对象
        QPen pen;                          //新建一个 QPen 对象
        pen.setStyle((Qt::PenStyle)style);//(a)
        pen.setWidth(weight);                 //设置画笔的线宽值
        pen.setColor(color);                  //设置画笔的颜色
        painter->begin(pix);                  //(b)
        painter->setPen(pen);                 //将 QPen 对象应用到绘制对象中
        painter->drawLine (p1, p2);
        painter->end();
        win_update();                            //重绘绘制区窗体
        delete painter;
    }

    void fillRect(QPoint p1,QPoint p2)
    {
        int x1=p1.x();
        int y1=p1.y();
        int x2=p2.x();
        int y2=p2.y();

        int x,y,w,h;
        if(x1<=x2)
        {
            x=x1;
            w=x2-x1;
        }
        else
        {
            x=x2;
            w=x1-x2;
        }
        if(y1<=y2)
        {
            y=y1;
            h=y2-y1;
        }
        else
        {
            y=y2;
            h=y1-y2;
        }

        QRectF p(x,y,w,h);

        QPainter *painter= new QPainter;   //新建一个 QPainter 对象
        QPen pen;                          //新建一个 QPen 对象
        pen.setStyle((Qt::PenStyle)style);//(a)
        pen.setWidth(weight);                 //设置画笔的线宽值
        pen.setColor(color);                  //设置画笔的颜色
        painter->begin(pix);                  //(b)
        painter->setPen(pen);
        QBrush b(color);            //将 QPen 对象应用到绘制对象中
        painter->fillRect (p,b);
        painter->end();
        win_update();                            //重绘绘制区窗体
        delete painter;
    }

    void setStyle(int s)
    {
        style = s;
    }
    void setWidth(int w)
    {
        weight = w;
    }
    void setColor(QColor c)
    {
        color = c ;
    }
    void clear(void)
    {
        win_upsize();
        delete pix;
        pix =new QPixmap (size());
        pix->fill (back_color);
        win_update();
    }
    void setBack(QColor c)
    {
        back_color = c;
        clear();
    }

    void setTextFont(QString strfont,int size)
    {
        QFont font(strfont, size);
        textFont = font;
    }

    void setTextStyle(int text_style)
    {
        textStyle = text_style;
    }

private:
    QWidget * widget;
    QPixmap *pix;
    QPoint doublePos;
    QPoint movePos;
    QPoint startPos;
    QPoint endPos;
    QFont textFont;
    int textStyle;
    int style;
    int weight;
    QColor color;
    QColor back_color;

    void win_upsize(void)
    {
        if(widget!=nullptr)
        {
            int w,h;
            w=widget->width();
            h=widget->height();
            if(this->width() < w || this->height() < h)
            {
                win_resize(w,h);
            }
        }
    }
    void win_update(void)
    {
        if(widget!=nullptr)
        {
            widget->update();
        }
        this->update();
    }
    void win_resize(int w,int h)
    {
        this->resize(w,h);
        delete pix;
        pix =new QPixmap (size());         //对此QPixmap对象用于准备随时接收绘制的内容
        pix->fill(back_color);             //填充背景色为白色
    }
};

#endif // MY_QT_DEF_H
